import React, { Component } from 'react'
import axios from "axios"
import Fenye from "./fenye"
 class App extends Component {
   state = {
       arr:[],
       index:1,
       total:0,
       kong:[]
   }
   checkPage(ind){
        this.setState({
            index:ind
        })
   }
  componentDidMount(){
      axios.get("/list").then(res=>{
           let arr1 = [];
           for(let i = 1;i<=Math.ceil(res.data.list.length/5);i++){
               arr1.push(i)
           }
          this.setState({
              arr:res.data.list,
              total:Math.ceil(res.data.list.length/5),
              kong:arr1
            //   kong.length = this.state.total
          })
        //   this.state.kong.length = this.state.total
        //   console.log(this.state.kong.length);
      })
  }
  render() {
    let arr2 = Array.from({length:this.state.total})
    console.log(arr2);
    let list = this.state.arr.slice((this.state.index - 1) * 5, this.state.index *5)
    console.log(this.state.kong.length);
    console.log("wocoa");
    return (
      <div>
          {
              list&&list.length?list.map((item,index)=>{
                    return <div key={index}>
                         <span>{item.name1}</span>
                         <span>{item.address}</span>
                         <span>{item.date}</span>
                    </div>
              }):""
          }
        
        {/* {
            
            this.state.kong.length?this.state.kong.map((item,index)=>{
                return <span onClick={this.checkPage.bind(this,item)}>{item}</span>
            }):"暂无fenye"
        } */}
        {/* {
            arr2&&arr2.length>0?arr2.map((item,index)=>{
                debugger
                return <span>{index+1}</span>
            }):""
        } */}

       {/* {
           for(let i = 0;i<globalThis.state.total;i++){
                <span></span>
           }
       } */}
         
        
      </div>
    )
  }
}

export default App